<template>
  <div>
    <div class="toolbar">
      <el-button type="primary" v-if="hasRight('create')" @click="showDetail('create')">新增</el-button>
      <el-button type="primary" v-if="hasRight('edit')">修改</el-button>
      <el-button type="primary" v-if="hasRight('del')">删除</el-button>
      <el-button type="primary" v-if="hasRight('query')">查询</el-button>
    </div>
    <el-table :data="users" v-loading="loading">
      <el-table-column prop="userName" label="用户名" width="180"></el-table-column>
      <el-table-column prop="email" label="Email"></el-table-column>
      <el-table-column prop="mobilePhoneNumber" label="手机号"></el-table-column>
      <el-table-column label="操作" width="120" inline-template align="center">
        <el-button @click="showDetail(row.pkid)" type="text" size="small">查看详情</el-button>
      </el-table-column>
    </el-table>
    <el-pagination class="page"
      @current-change="handleCurrentChange"
      :current-page="1"
      :page-size="10"
      layout="total, prev, pager, next, jumper"
      :total="page.totalRecord">
    </el-pagination>
  </div>
</template>
<style scoped>
  .page{
    text-align: right;
    margin: 10px 0px;
  }
</style>
<style>
  .toolbar{
    padding: 10px;
  }
</style>
<script>
  import userApi from '../../../api/sys/userApi'
  import mixin from '../../../mixin/rights'

  export default {
    data () {
      return {
        users: [],
        page: {},
        loading: false
      }
    },
    mixins: [mixin],
    created () {
      this.loading = true
      userApi.queryAll(1, 10).then((resp) => {
        this.users = resp.body.data
        this.page = resp.body.page
        this.loading = false
      })
    },
    methods: {
      handleCurrentChange: function (pageNo) {
        this.loading = true
        userApi.queryAll(pageNo, 10).then((resp) => {
          this.sysUsers = resp.body.data
          this.loading = false
        })
      },
      showDetail: function (id) {
//        this.$store.dispatch('updateActiveUser', sysUser)
        this.$router.push({name: 'm-u-d', params: {id: id}})
      }
    }
  }
</script>
